layui.define(['layer', 'vip_nav', 'jquery', 'element', 'base64', 'cookie'], function (exports) {
    "use strict";

    var $ = layui.jquery,
        vipNav = layui.vip_nav,
        layerTips = parent.layer === undefined ? layui.layer : parent.layer,
        layer = layui.layer,
        base64 = layui.base64,
        element = layui.element;


    var common = {
        //返回值：arg1乘以arg2的精确结果
        accMul: function (arg1, arg2) {
            var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
            try {
                m += s1.split(".")[1].length;
            } catch (e) {
            }
            try {
                m += s2.split(".")[1].length;
            } catch (e) {
            }
            return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
        },

        //返回值：arg1加上arg2的精确结果
        accAdd: function (arg1, arg2) {
            var r1, r2, m;
            try {
                r1 = arg1.toString().split(".")[1].length;
            } catch (e) {
                r1 = 0;
            }
            try {
                r2 = arg2.toString().split(".")[1].length;
            } catch (e) {
                r2 = 0;
            }
            m = Math.pow(10, Math.max(r1, r2));
            return (arg1 * m + arg2 * m) / m;
        },
        //返回值：arg1减上arg2的精确结果
        accSub: function (arg1, arg2) {
            return accAdd(arg1, -arg2);
        },

        /**
         * 抛出一个异常错误信息
         * @param {String} msg
         */
        throwError: function (msg) {
            throw new Error(msg);
            return;
        },
        /**
         * 弹出一个错误提示
         * @param {String} msg
         */
        msgError: function (msg) {
            layer.msg(msg, {
                icon: 5
            });
            return;
        },
        //返回上页
        back: function () {
            window.history.back(-1);
        },

        checkSocialCreditCode: function (Code) {
            var patrn = /^[0-9A-Z]+$/;
            //18位校验及大写校验
            if ((Code.length != 18) || (patrn.test(Code) == false)) {
                console.log("不是有效的统一社会信用编码！");
                return false;
            } else {
                var Ancode;//统一社会信用代码的每一个值
                var Ancodevalue;//统一社会信用代码每一个值的权重
                var total = 0;
                var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加权因子
                var str = '0123456789ABCDEFGHJKLMNPQRTUWXY';

                //不用I、O、S、V、Z
                for (var i = 0; i < Code.length - 1; i++) {
                    Ancode = Code.substring(i, i + 1);
                    Ancodevalue = str.indexOf(Ancode);
                    total = total + Ancodevalue * weightedfactors[i];
                    //权重与加权因子相乘之和
                }
                var logicCheckCode = 31 - total % 31;
                if (logicCheckCode == 31) {
                    logicCheckCode = 0;
                }
                var Str = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";
                var Array_Str = Str.split(',');
                logicCheckCode = Array_Str[logicCheckCode];


                var checkCode = Code.substring(17, 18);
                if (logicCheckCode != checkCode) {
                    console.log("不是有效的统一社会信用编码！");
                    return false;
                } else {
                    console.info("统一社会信用编码OK");
                    return true;
                }
            }
        },
        checkFox: function (fox) {
            //传真号验证
            if (fox != null && fox != "") {
                // credit: jquery.h5validate.js / orefalo
                //var rag = "^([+][0-9]{1,3}[ .-])?([(]{1}[0-9]{2,6}[)])?([0-9 .-/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$";
                var rag =  "^([0-9]{3,4}-)?[0-9]{7,8}$";
                if (!new RegExp(rag).test(fox)) {
                    console.log("无效的传真号码");
                    return false;
                }
                return true;
            }
            return true;
        },


        /**
         * 弹出层
         * @param options
         */
        showAjaxDiag: function (options) {
            var addBoxIndex = -1, area = options.area || ['600px', '400px'];
			
			var htmlUrl=options.url;
			if(htmlUrl.indexOf('?')!=-1){
				htmlUrl+='&v_v='+develop.version;
			}else{
				htmlUrl+='?v_v='+develop.version;
			}
			console.log(htmlUrl)
            var msg = -1;
            if (addBoxIndex !== -1) {
                return;
            } else {
                //本表单通过ajax加载 --以模板的形式，当然你也可以直接写在页面上读取
                $.ajax({
                    url: htmlUrl,
                    type: options.type || "get",
                    timeout: 20000,
                    data: options.data || {},
                    dataType: "html",
                    cache: false,
                    beforeSend: function () {
                        msg = parent.layer.msg(options.laodMsg || '加载中', {icon: 16, shade: 0.01, time: 0});
                    },
                    contentType: " application/x-www-form-urlencoded;charset=utf-8",
                    complete: function () {
                        if (msg != -1) {
                            parent.layer.close(msg);
                        }
                    },
                    success: function (form) {
                        addBoxIndex = layerTips.open({
                            type: 1,
                            skin: options.skin || 'layer-default',
                            title: options.title || false,
                            content: form,
                            shade: 0.1,
                            closeBtn: options.closeBtn,
                            move: options.move || '.layui-layer-title',
                            /* scrollbar: false,*/
                            offset: options.offset || ['100px', '30%'],
                            area: area,
                            zIndex: options.zIndex,
                            maxmin: options.maxmin || false,
                            full: function (elem) {
                                var win = window.top === window.self ? window : parent.window;
                                $(win).on('resize', function () {
                                    var $this = $(this);
                                    elem.width($this.width()).height($this.height()).css({
                                        top: 0,
                                        left: 0
                                    });
                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                });
                            },
                            success: function (layero, index) {
                                var form = parent.parentForm;
                                //form.render();
                                var body_box = $(layero).find('#body_box');
                                if (body_box) {
                                    $(layero).find("div[class='layui-layer-content']").removeClass();
                                    var h = parseInt(area[1].replace("px", "")) - 50;
                                    if (options.title != "" && options.title != undefined) {
                                        h -= 44;
                                    }
                                    body_box.height(h + "px");
                                }
                                options.onSuccess(layero, index, form);

                            },
                            cancel: function(index, layero){
                                if(options.cancel){
                                    options.cancel(index, layero);
                                }
                            },
                            end: function () {
                                addBoxIndex = -1;
                            }
                        });

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        parent.layer.msg('网络异常', {icon: 5});
                    }
                });
            }
        },

        /**
         * 封装ajax,用于 table 的列表操作
         * @param  options：ajax 请求参数
         * isCover:是否load全覆盖（isCover：单页面覆盖，不包括菜单）
         */
        doAjax: function (options) {
            var msg = -1,url='';
            var params = API.parms;
            //默认后台不缓存
            if (cache == false || cache == undefined) {
                params = $.extend({cache: true}, params);
            }
            params["rand"] = new Date().toLocaleTimeString();
            var data = options.data;
            if (data == undefined) {
                data = {};
            }
            var jsonString = JSON.stringify($.extend(data, params));
            var reqData = {jsonString: base64.encode(jsonString)};
            var cache = options.cache;

            var load = true;
            if (options.load == false) {
                load = false;
            }
            if(options.scfToAbs){
                url=API.action_url_abs + options.action
            }else if(options.Kawing){
                url=API.action_url_kawing + options.action
            }else{
                url=API.action_url + options.action
            }
            if (develop.isPrintUrl && window.applicationCache) {
                console.log(url+ "&jsonString=" + base64.encode(jsonString));
            }
            var tips=layerTips;
            //false 单页面load覆盖
            if(options.isCover==false){
                tips=layer;
            }

            $.ajax({
                url: url,
                type: options.type || "GET",
                timeout: options.timeout || 20000,
                data: reqData,
                cache: false,
                dataType: options.dataType || "json",
                async: options.async || true,
                corssDomain:true,
                beforeSend: function (data) {
                    if (options.beforeSend == undefined) {
                        if (load == true) {
                            msg = tips.msg(options.loadMsg || '加载中', {icon: 16, shade: 0.01, time: 0});
                        }
                    } else {
                        options.beforeSend(data);
                    }
                },
                contentType: options.contentType || "application/x-www-form-urlencoded;charset=utf-8",
                complete: function () {
                    if (msg != -1 && options.beforeSend == undefined) {
                        tips.close(msg);
                    }
                    if(status == 'timeout') {
                        tips.msg('网络异常', {icon: 5});
                    }
                },
                success: function (data) {
                    if (options.success != undefined) {
                        options.success(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (options.error != undefined) {
                        options.error(XMLHttpRequest, textStatus, errorThrown);
                    } else {
                        tips.msg(options.errMsg || '网络异常', {icon: 5});
                    }
                }
            });
        },

        /**
         * 封装ajax,用于 table 的列表操作
         * @param  options：ajax 请求参数
         */
        doAjaxUpload: function (options) {
            var msg = -1;
            var params = API.parms;
            //默认后台不缓存
            if (cache == false || cache == undefined) {
                params = $.extend({cache: true}, params);
            }
            params["rand"] = new Date().toLocaleTimeString();
            var data = options.data;
            if (data == undefined) {
                data = {};
            }
            if(data.fileBase64 && data.fileBase64.indexOf('base64,') != -1 ){
                data.fileBase64 = data.fileBase64.substring(data.fileBase64.indexOf('base64,')+7)
            }
            
            var jsonString = JSON.stringify($.extend(data, params));
            var reqData = {jsonString: base64.encode(jsonString)};
            var cache = options.cache;

            var load = true;
            if (options.load == false) {
                load = false;
            }
            if (develop.isPrintUrl && window.applicationCache) {
               console.log("请求信息：" + JSON.stringify(API.upload_url + options.action + "&jsonString=" + base64.encode(jsonString)));
            }

            $.ajax({
                url: API.upload_url + options.action,
                type: options.type || "GET",
                timeout: options.timeout || 30000,
                data: reqData,
                cache: false,
                dataType: options.dataType || "json",
                async: options.async || true,
                beforeSend: function (data) {
                    if (options.beforeSend == undefined) {
                        if (load == true) {
                            msg = layerTips.msg(options.loadMsg || '加载中', {icon: 16, shade: 0.01, time: 0});
                        }
                    } else {
                        options.beforeSend(data);
                    }
                },
                contentType: options.contentType || "application/x-www-form-urlencoded;charset=utf-8",
                complete: function () {
                    if (msg != -1 && options.beforeSend == undefined) {
                        layerTips.close(msg);
                    }
                },
                success: function (data) {
                    if (options.success != undefined) {
                        options.success(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (options.error != undefined) {
                        options.error(XMLHttpRequest, textStatus, errorThrown);
                    } else {
                        layerTips.msg(options.errMsg || '网络异常', {icon: 5});
                    }
                }
            });
        },


        /**
         * 封装ajax
         * @param  options：ajax 请求参数
         */
        ajax: function (options) {
            var msg = -1;
            $.ajax({
                url: options.url,
                type: options.type || "GET",
                timeout: options.timeout || 15000,
                data: options.data || {},
                dataType: options.dataType || "json",
                async: options.async || true,
                beforeSend: function (data) {
                    if (options.beforeSend == undefined) {
                        msg = layerTips.msg(options.loadMsg || '加载中', {icon: 16, shade: 0.01, time: 0});
                    } else {
                        options.beforeSend(data);
                    }
                },
                contentType: options.contentType || "application/x-www-form-urlencoded;charset=utf-8",
                complete: function () {
                    if (msg != -1) {
                        layerTips.close(msg);
                    }
                },
                success: function (data) {
                    if (options.success != undefined) {
                        options.success(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (options.error != undefined) {
                        options.error(XMLHttpRequest, textStatus, errorThrown);
                    } else {
                        layerTips.msg(options.errMsg || '网络异常', {icon: 5});
                    }
                }
            });
        },


        /**
         * 根据url的name 获取参数值
         */
        getQueryString: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return null;
        },

        //菜单数组分级处理
        menuListDispose: function (menuList) {
            var menuArr = new Array();
            for (var i = 0; i < menuList.length; i++) {
                if (!menuList[i].menuId) {
                    menuArr.push(menuList[i]);
                    var num = menuArr.length - 1;
                    menuArr[num].list = new Array();
                    for (var x = 0; x < menuList.length; x++) {
                        if (menuList[x].menuId == menuList[i].id) {
                            menuArr[num].list.push(menuList[x]);
                        }
                    }
                }
            }
            return menuArr;
        },

        /**
         *  获取table “多选框” 的 值（返回数据是 “数组”）
         * options:{
    	 *  keyData:'id' //keyId, 获取 批量获取id（数据）数组
    	 *  table: layUI table 实例
    	 * }
         */
        getTdData_Arry: function (options) {
            var checkStatus = options.table.checkStatus('dataCheck'), data = checkStatus.data;
            var arr = [];
            $(data).each(function (i, v) {
                arr.push(v[options.keyData]);
            });
            return arr;
        },
        //页面跳转，可以后退
        href: function (url) {
			var htmlUrl=encodeURI(url);
			if(htmlUrl.indexOf('?')!=-1){
				htmlUrl+='&v_v='+develop.version;
			}else{
				htmlUrl+='?v_v='+develop.version;
			}
            location.href = htmlUrl;
        },
        //菜单点击跳转
        hrefMenu: function (htmlName) {
            var el = $('.layui-nav-child dd a', window.parent.document);
            var len=el.length;
            for (var i =0;i<len;i++) {
                var uri=$(el[i]).attr('href-url');
                if(uri){
                    if (uri.indexOf(htmlName) != -1) {
                        el[i].click();
                        $(el[i]).parents('.layui-nav-child').prev().get(0).click();
                        return false;
                    }
                }
            }
        },

        //页面跳转，不能后退
        replaceHref: function (url) {
			var htmlUrl=encodeURI(url);
			if(htmlUrl.indexOf('?')!=-1){
				htmlUrl+='&v_v='+develop.version;
			}else{
				htmlUrl+='?v_v='+develop.version;
			}
            location.replace(htmlUrl);
        },
        //禁止页面返回
        killBack: function killBack() {
            window.history.forward(1);
        },
        //数字保留2位小数，如8.9999 转为8.99
        toFixed2: function (num) {
            if (isNaN(num)) {
                return 0.00;
            }
            return parseFloat(+num.toFixed(2));
        },

        /**
         * 消息提示
         * @param {Object} message：提示语
         * @param {Object} options{
         * 	 time：时间毫秒 如：1000（1秒）
         *    callBack：回调函数（如 提示后跳转页面）
         * }
         */
        msg: function (message, options) {
            var time = 2000;
            // if (options !== undefined && options.callBack !== undefined) {
            //     time = 2000;
            // }
            layerTips.msg(message, {time: time || options.time}, function () {
                if (options !== undefined && options.callBack !== undefined) {
                    options.callBack();
                }
            });
        },
        //服务器图片路径
        getServerPath: function () {
            var imageServerPath = global_img_url;
            return imageServerPath;
        },
        /**
         * 过滤object属性是""的数据
         * obj:object 对象
         **/
        filterObject: function (obj) {
            if (obj !== undefined) {
                for (var i in obj) {
                    var val = obj[i];
                    if(typeof(obj[i])=='string'){
                    	obj[i]=$.trim(obj[i])//去掉字符串前后的空格
                    }
                    if (val == "") {
                        delete obj[i];
                    }
                }
            }

            return obj;
        },
        isArray: function (arr) {
            return typeof arr == "object" && arr.constructor == Array;
        },
        /**
         * 刷新table，（不会从第一页查询）
         */
        reloadTable: function () {
            $(".layui-laypage-btn")[0].click();
        },

        /**
         *  控件数据 转为 js 数据
         * @param {Object} obj  输入的数据
         * @param {Object} index 数据索引
         **/
        getfileStr: function (obj, index) {
            if (obj !== undefined) {
                if (common.isArray(obj)) {
                    return obj[index];
                } else {
                    return obj;
                }
            }
        },
        /**
         *   删除obje 指定的的key
         * @param {Object} options{
         	data:object 对象
         * 	,arry:需要删除的数组如 ['id','name']
         * 	例子：fmsUtil.delObjectKey({
						data:fileds,
        				 arry:['id','name']
					})
         * }
         */
        delObjectKey: function (options) {
            for (var obj in options.data) {
                for (var key in options.arry) {
                    var ss = keyArry[key]
                    if (obj == keyArry[key]) {
                        delete[obj];
                    }
                }
            }
        },

        /**
         * 将form分散的field  封装成数组对象
         * @param options{
    *   keys: 需要封装的字段数组 如["goodsName",'mark',{"packageType":"packageType1"}(前面是打包的key，后面是控件名称)]
        *   rows:对象个数，一般用于
        *   field:form里面fields}*/
        packFiledToArry: function (options) {
            var arr = [], keys = options.keys, field = options.field, rows = options.rows;
            for (var i = 0; i < rows; i++) {
                var obj = {};
                for (var k = 0; k < keys.length; k++) {
                    var key = keys[k], setKey = keys[k]; //获取key名称，保存key名称

                    if (key.constructor == Object) {
                        for (var o in key) {
                            setKey = o;
                            key = key[Object.keys(key)];
                        }
                    }
                    var values = field[key];//根据key 取值
                    if (values.constructor == Array) {
                        obj[setKey] = values[i];
                    } else {
                        obj[setKey] = values;
                    }
                }
                arr.push(obj);
            }

            return arr;
        },
        /**
         *
         * @param {Object} options
         * 用法 fmsUtil.changeFrameTab({.....});
         * {
         * 	layFilter：过滤器名字
         *  cotentId：内容容器的id
         *  src:
         * }
         *
         */
        changeFrameTab: function (options) {

            var layid = location.hash.replace('/^#"' + options.layFilter + '"=/', '');
            element.tabChange('"' + options.layFilter + '"', layid);
            element.on('tab(' + options.layFilter + ')', function (elem) {
                var index = elem.index;//tab 索引
                var $target = $(options.cotentId).find(".layui-tab-item:eq(" + index + ")");
                var url = pathUrl + $target.attr("data-src");
                // location.hash = 'test='+ $(this).attr('lay-id');
                if (index > 0) {
                    // $(options.cotentId).find(".layui-tab-item:eq("+index+")").html('<iframe scrolling="no" frameborder="no" border="0" width="100%" src= '+options.cotentUrl+'></iframe>')
                    $(options.cotentId).find(".layui-tab-item:eq(" + index + ")").html('<iframe scrolling="no" frameborder="no" border="0" style="min-height:300px;" width="100%" src= ' + url + '></iframe>')
                }
            });
        },
        /**
         * 添加iframe
         * @param url： iframe  url
         * @returns {string}
         */
        addIframe: function (url) {
            return '<iframe scrolling="no" frameborder="no" border="0" style="min-height:300px;" width="100%" src= ' + url + '></iframe>';
        },

        /**
         * 用户解决被 iframe嵌套的页面，用于设置高度 默认是 1000px；
         * @param {Object} contentH
         */
        loadIframeHeight: function (contentH) {
            if ($(window.frameElement).attr("src") != undefined) {
                var bodyH = $(document).height();
                var setH = 0, h = 1000;

                if (contentH !== undefined) {
                    setH = contentH;//设置高度
                } else {
                    if (bodyH > h) {
                        setH = bodyH + 100; //所有浏览器屏幕+100
                    } else {
                        setH = h;//设置1000
                    }
                }

                $(window.frameElement).height(setH);
            }
        },

        //引用模板方法的封装
        /**
         * @param {Object} optins{
		   * 	scriptId：模板id
	      *     data：aip数据
		   *    viewId：展示容奇
		   *    callBack:回调处理函数
		   * }
         */
        deposit: function (optins) {
            //没有渲染之前的函数调用
            if (optins.beforeCallBack !== undefined) {
                optins.beforeCallBack();
            }
            var html = template(optins.scriptId, optins.data);
            $(optins.viewId).html(html);

            //渲染处理后的函数调用
            if (optins.callBack !== undefined) {
                return optins.callBack();
            }
        },

        /**
         * 渲染填充 加载“动态数据”的 select 控件
         * @param options{
         * parentId {1.币种 2.科目类型 3.客户分类 4.运输方式 5.资产类别 6.折旧方法 7.计量单位 8.运输条款 9.包装类型}
         * selector：jquery 选择器名 如： $("#id")
         * form: layui form 模块化的实列对象
         * }
         */
        renderSingleSelect: function (options) {
            this.getLevelCategory({
                parentId: options.parentId,
                callback: function (res) {
                    var $selector = options.selector;
                    /**
                     * 渲染控件
                     * @type {string}
                     */
                    var html = '<option value="">请选择</option>';
                    $(res).each(function (i, data) {
                        html += '<option value="' + data.id + '">' + data.name + '</option>'
                    });
                    $selector.html(html);

                    $selector.each(function (k, obj) {
                        var $target = $(obj);
                        var selectVal = $target.attr("data")
                        if (selectVal !== undefined) {
                            $target.val(selectVal);
                        }
                    });
                    options.form.render("select");
                }
            });
        },

        /**
         * 渲染填充 select 控件(select数据是静态的，不需要动态读取的)
         * @param options{
         * selector：jquery 选择器名 如： $("#id")
         * form: layui form 模块化的实列对象
         * }
         */
        renderSingleSelectStatic: function (options) {
            var $selector = options.selector;
            $selector.each(function (k, obj) {
                var $target = $(obj);
                var selectVal = $target.attr("data");
                if (selectVal !== undefined) {
                    $target.val(selectVal);
                }
            });

            options.form.render("select");
        },

        /**
         * 根据action 渲染select 控件
         * @param options{
         * 	action:接口名称
         * data：
         * selector：
         * form：
         * }
         */
        renderSelectByAction: function (options) {
            common.doAjax({
                action: options.action,
                data: options.data,
                type: "get",
                load: false,
                success: function (result) {
                    if (result.isSuccess == true) {
                        options.selector.empty();
                        var html = '<option value="">请选择</option>'
                        if (options.isDefault == false) {
                            html = '';
                        }

                        $(result.data).each(function (i, item) {
                            //departmentsDetails +='<option value="'+item.id+'">'+item.name+'</option>';
                            html += '<option value="' + item[options.filedId] + '">' + item[options.filedName] + '</option>';
                        });

                        options.selector.html(html);

                        //渲染
                        common.renderSingleSelectStatic({
                            selector: options.selector,
                            form: options.form
                        });
                    } else {
                        common.msg(result.description)
                    }
                }
            });
        }
    };

    //公共数据
    var commData = {
        /***
         * 用于select（单个） 控件
         * @param {optins} parentId {1.币种 2.科目类型 3.客户分类 4.运输方式 5.资产类别 6.折旧方法}
         *  callback:回调函数（方法里面可返回数据）
         */
        getLevelCategory: function (optins) {

            common.doAjax({
                action: "categoryService.get1LevelCategoryDicByParentId",
                data: {parentId: optins.parentId},
                load: false,
                type: 'get',//请求方式
                success: function (data) {
                    if (data.isSuccess == true) {
                        var dt = data.data;
                        /*arry.paush({id:dt.id,name:dt.name,remark:dt.remark});*/
                        optins.callback(dt);
                    } else {
                        common.msg(data.description);
                    }
                }
            });

            return optins.callback;
        }
    };

    var mudule = $.extend(common, commData);

    var user = $.cookie(userKey);

    API["userId"] = function () {
        if (user !== undefined && user !== "null") {
            var userStr = base64.decode(user);
            var object = JSON.parse(userStr);
            return object.userId;
        } else {
            // parent.location.replace(pathUrl + "/login.html");
        }
    };

    API["operatorId"] = function () {
        if (user !== undefined && user !== "null") {
            var userStr = base64.decode(user);
            var object = JSON.parse(userStr);
            return object.operatorId;
        } else {
            // alert()
            // common.replaceHref(pathUrl + "/login.html");
           // parent.location.replace(pathUrl + "/login.html");
        }
    };

    API["account"] = function () {
        if (user !== undefined && user !== "null") {
            var userStr = base64.decode(user);
            var object = JSON.parse(userStr);
            return object.account;
        } else {
            // common.replaceHref(pathUrl + "/login.html");
            // parent.location.replace(pathUrl + "/login.html");
        }
    };

    API["ip"] = function () {
        if (user !== undefined && user !== "null") {
            var userStr = base64.decode(user);
            var object = JSON.parse(userStr);
            return object.ip;
        } else {
            // common.replaceHref(pathUrl + "/login.html");
            // parent.location.replace(pathUrl + "/login.html");
        }
    };

    API["systemSourceId"] = function () {
        var systemId = "402881fe6223e385016223e903bb0000";
        return systemId;
    };


    API["companyURL"] = function () {
        var url = "html/common/company/";
        return url;
    };

    API["systemURL"] = function () {
        var url = "html/operate/system/";
        return url;
    };

    /**
     *
     * @param type  BACKSTAGE==运营总后台;
     *              ENTERPRISE_CORE==核心企业后台;
     *              ENTERPRISE_SUPPLIER==供应商后台;
     *              USER_CENTER==会员中心;
     * @returns {*}
     */
    var pathname = window.location.pathname;
    if (pathname.indexOf('login.html') == -1) {
        /* if(user==null  || user=="null"){
            common.replaceHref(pathUrl+"/login.html");
         }*/
    }

    //返回
    $(document.body).on("click", 'button[lay-back]', function () {
        var url = $(this).attr("lay-back");
        if (url !== undefined && url != "") {
            common.replaceHref(url);
        } else {
            common.back();
        }
    });

    exports('fms_util', mudule);
});